﻿using LitJson;
using LNet;
using OestsCommon.Model;
using OestsDataBase;
using OestsServer.Net;
using System;

namespace OestsServer.Handlers.OESPHandlers
{
    public class HandInTheoryExamHandler : HandlerBase<OESPClientChannel>
    {
        public override PacketKey PKey
        {
            get
            {
                return PacketKey.HandInTheoryExam;
            }
        }

        public override void Execute(OESPClientChannel client, Request resquestPacket)
        {
            base.Execute(client, resquestPacket);

            //得到客户端提交的数据
            ExamData data = JsonMapper.ToObject<ExamData>(resquestPacket.DataStr);
            data.Date = DateTime.Now.ToString();
            //在理论成绩表中添加数据
            if (StudentExamDAL.HandInExamGrade(data))//提交成功
            {
                //if (StudentExamDAL.UpdateExamCount(data.StudentId, data.ExamId))
                //    data.Count++;
                ResponsePacket.ReturnCode = ReturnCode.Success;
            }

            ResponsePacket.DataObject = data;
            client.Send(ResponsePacket);

            Response response = new Response(PacketKey.BroadcastExamDataToTeacher, data)
            {
                ReturnCode = ReturnCode.Success
            };

            OESPClientChannel.BrocastToTeacher.Dispatch(response);
        }

    }
}
